package com.devMode.DecoratorMode;

/**
 * 装饰器模式 Ⅱ
 */
public class DecoratorMode2 {
    public static void main(String[] args) {
        shape circle = new Circle();
        shape rectangle = new Rectangle();
        ShapeDecorator redCircle = new RedShapeDecorator(circle);
        circle.draw();
        redCircle.draw();

    }
}

interface shape{
    void draw();
}

class Rectangle implements shape{

    @Override
    public void draw() {
        System.out.println("Shape : Rectangle");
    }
}

class Circle implements shape{

    @Override
    public void draw() {
        System.out.println("shape : Circle");
    }
}

/**
 * 抽象修饰类
 */
abstract class ShapeDecorator implements shape{
    protected shape dercoratedShape;

    public ShapeDecorator(shape dercoratedShape){
        this.dercoratedShape = dercoratedShape;
    }

    public void draw(){
        dercoratedShape.draw();
    }
}

class RedShapeDecorator extends ShapeDecorator{

    public RedShapeDecorator(shape dercoratedShape) {
        super(dercoratedShape);
    }

    @Override
    public void draw(){
        dercoratedShape.draw();
        decorate();
    }

    public  void decorate(){
        System.out.println("decorate !!!");
    }
}
